﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using CommonUtility;
using System.Web.Script.Serialization;
using Model;
namespace WebApplication
{
    public partial class RoleFunction : BasePage
    {
        const string FUN_ID = "FA04";
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Common.ToString(Request["Action"]);
            switch (action)
            {
                case "GetRolePermission":
                    Response.Write(GetRolePermission());
                    Response.End();
                    break;
                case "Save":
                    Response.Write(DataSave());
                    Response.End();
                    break;
                case "LoadColumn":
                    Response.Write(LoadColumn());
                    Response.End();
                    break;
                case "LoadFun":
                    Response.Write(LoadFun());
                    Response.End();
                    break;
                case "GetRolesList":
                    Response.Write(GetRolesList());
                    Response.End();
                    break;
            }
            if (!IsPostBack && string.IsNullOrEmpty(action))
            {
                bllPermission Perm = new bllPermission(oUser.UserID, FUN_ID);
                hdPermission.Value = new JavaScriptSerializer().Serialize(Perm);
            }
        }

        /// <summary>
        /// 加载flag为"A"的Role
        /// </summary>
        /// <returns></returns>
        private string GetRolesList()
        {
            return new bllRole().GetAllRole(" [flag] = 'A'", oUser);
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <returns></returns>
        private string GetRolePermission()
        {
            return new bllRoleFunction().GetRolePermission(Common.ToString(Request["RoleID"]), oUser);
        }

        /// <summary>
        /// 加载方法
        /// </summary>
        /// <returns></returns>
        private string LoadFun()
        {
            return new bllRoleFunction().LoadFun(Common.ToString(Request["where"]), oUser);
        }

        /// <summary>
        /// 加载列
        /// </summary>
        /// <returns></returns>
        public string LoadColumn()
        {
            return new bllRoleFunction().LoadColumn(oUser);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        protected string DataSave()
        {
            string roleid = Common.ToString(Request["roleid"]);
            string datajson = Request["DataJSON"];
            return new bllRoleFunction().DataSave(FUN_ID, datajson, roleid, oUser);
        }
    }
}